package com.bluefeather.songlyric;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
	
	private int		_count = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
		PreferenceManager.setDefaultValues(this, R.layout.layout_settings, false);
		PreferenceManager.getDefaultSharedPreferences(SongLyricApp.instance())
			.registerOnSharedPreferenceChangeListener(this);
		_count = 0;
	}

	public static class SettingsFragment extends PreferenceFragment {
		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			addPreferencesFromResource(R.layout.layout_settings);
		}
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sp, String key) {
		if(key.equals("BG_PICTURE"))
			if(++_count % 10 == 0) {
				int mode = sp.getInt("AUTHOR_MODE", DB.AUTHOR_FAMOUS);
				if(++mode > DB.AUTHOR_SELF)
					mode = DB.AUTHOR_FAMOUS;
				Editor editor = sp.edit();
				editor.putInt("AUTHOR_MODE", mode);
				editor.commit();
				SongLyricApp.instance().showToast("AUTHOR_MODE changed");
			}
	}

}
